<?php

/*
 * -------------------------------------
 * www.dlancedu.com | Jaisiel Delance
 * framework mvc basico
 * Bootstrap.php
 * -------------------------------------
 */


class Bootstrap
{   
    public static function run(Request $peticion)
    {
        
        $controller_file_name = $peticion->getController() . SUFFIX_FILE_CONTROLLER . '.php';
        $controller_class_name = ucfirst($peticion->getController()) . SUFFIX_CLASS_CONTROLLER;

        $rutaControlador = CONTROLLER_PATH . $controller_file_name;
        $metodo = $peticion->getMethod();
        $args = $peticion->getArgs();
        
        if(is_readable($rutaControlador)){
            require_once $rutaControlador;
            $controller = new $controller_class_name;
            
            if(is_callable(array($controller, $metodo))){
                $metodo = $peticion->getMethod();
            }
            else{
                $metodo = 'index';
            }
            
            if(isset($args)){
                call_user_func_array(array($controller, $metodo), $args);
            }
            else{
                call_user_func(array($controller, $metodo));
            }
            
        } else {
            throw new Exception('no encontrado');
        }
    }
}

?>